package hibernate;

import java.util.Collection;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class driver {

	public static void main(String[] args) {
		
		SessionFactory sessionFactory = hibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		Transaction transaction = session.beginTransaction();
		try {
//			Students students = new Students();
//			students.setFirstName("Kadir");
//			students.setLastName("Yalcinkaya");
//			students.setDescription("Bilgisayar Programlama");
//			students.setYearDate(new Date());
//			{
//				PLanguages pLanguages= new PLanguages();
//				pLanguages.setLevel(3);
//				pLanguages.setProgramName("pascal");
//				students.getPlanguage().add(pLanguages);
//			}
//			
//			{
//				PLanguages pLanguages= new PLanguages();
//				pLanguages.setLevel(4);
//				pLanguages.setProgramName("java");
//				students.getPlanguage().add(pLanguages);
//			}
//			{
//				PLanguages pLanguages= new PLanguages();
//				pLanguages.setLevel(2);
//				pLanguages.setProgramName("delphi");
//				students.getPlanguage().add(pLanguages);
//			}
//			{
//				PLanguages pLanguages= new PLanguages();
//				pLanguages.setLevel(4);
//				pLanguages.setProgramName("my-sql");
//				students.getPlanguage().add(pLanguages);
//			}
			Students students = (Students) session.get(Students.class, 1L);
			System.out.println(students);
			Collection<PLanguages> pLanguage = students.getPlanguage();
			for (PLanguages pLanguages : pLanguage) {
				System.out.println(pLanguages);
			}
			
			session.save(students);
			transaction.commit(); 
		} catch (Exception e){
			transaction.rollback();
		}
		session.close();
		sessionFactory.close();

	}

}
